﻿Imports ScanFlow.Net.BEL
Imports ScanFlow.Net.BLL

Public Class frmIndex
    Dim indicesBL As IndicesBL

    Sub New()

        indicesBL = New IndicesBL
        InitializeComponent()

    End Sub

    Private Sub lnkNewIndice_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkNewIndice.LinkClicked
        Dim _frmIndexAdd As New frmIndexAdd
        _frmIndexAdd.ShowDialog()
        Call LoadList()
        _frmIndexAdd.Dispose()
    End Sub

    Private Sub frmIndex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call LoadList()
    End Sub

    Private Sub LoadList()
        lstvIndices.Items.Clear()

        Dim _datableIndices As DataTable = indicesBL.List
        Dim lviItem As ListViewItem

        For Each dtrFila As DataRow In _datableIndices.Rows
            lviItem = New ListViewItem
            lviItem.Text = dtrFila("IdIndice")
            lviItem.SubItems.Add(dtrFila("Nombre"))
            lviItem.SubItems.Add(dtrFila("TipoDatoDes"))
            lviItem.ImageIndex = 1
            lstvIndices.Items.Add(lviItem)
        Next

    End Sub

    Private Sub lnkUpdateIndice_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkUpdateIndice.LinkClicked
        If lstvIndices.SelectedItems.Count > 0 Then
            Call ShowFormListAdd(True, CShort(lstvIndices.SelectedItems(0).Text.Trim))
        End If
    End Sub

    Private Sub ShowFormListAdd(Optional ByVal bolUpdate As Boolean = Nothing, Optional ByVal idIndice As Short = 0)

        Dim frmIndexAdd As New frmIndexAdd
        frmIndexAdd.bolUpdate = bolUpdate
        frmIndexAdd.idIndice = idIndice
        frmIndexAdd.ShowDialog()
        frmIndexAdd.Dispose()

    End Sub

  
    Private Sub lstvIndices_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstvIndices.DoubleClick
        If lstvIndices.SelectedItems.Count > 0 Then
            Call ShowFormListAdd(True, CShort(lstvIndices.SelectedItems(0).Text.Trim))
        End If

    End Sub

    Private Sub SplitContainer1_Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles SplitContainer1.Panel2.Paint

    End Sub

    Private Sub lstvIndices_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstvIndices.SelectedIndexChanged

    End Sub

    Private Sub LinkLabel6_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel6.LinkClicked, LnkEliminarIndice.LinkClicked
        If MsgBox("Esta seguro de eliminar el indice [" & lstvIndices.SelectedItems(0).SubItems(1).Text & "]", MsgBoxStyle.YesNo + MsgBoxStyle.Question, Application.ProductName) = MsgBoxResult.Yes Then
            indicesBL.Eliminar(CInt(lstvIndices.SelectedItems(0).Text))
            LoadList()
        End If
    End Sub
End Class